package com.edu.koTA07.takingOrder;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.edu.koTA07.XmlToBean.BarangXmlSetToBean;
import com.edu.koTA07.XmlToBean.CustomerXmlSetToBean;
import com.edu.koTA07.XmlToBean.DiskonXmlSetToBean;
import com.edu.koTA07.XmlToBean.KategoriBarangXmlSetToBean;
import com.edu.koTA07.XmlToBean.PerusahaanXmlSetToBean;
import com.edu.koTA07.XmlToBean.SalesXmlSetToBean;


import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class Main extends TabActivity {
	
	private ViewFlipper mflipper ;
	TabHost host = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        setContentView(R.layout.main);
     
        new CustomerXmlSetToBean(Main.this);
		new BarangXmlSetToBean(Main.this);
		new KategoriBarangXmlSetToBean(Main.this);
		new SalesXmlSetToBean(Main.this);
		new PerusahaanXmlSetToBean(Main.this);
		new DiskonXmlSetToBean(Main.this);
        initButton();
        mflipper.startFlipping();
        setHeaderDate();
        mflipper.stopFlipping();
        actionScreen();
        
    }

	private void setHeaderDate() {
        String dateString = new SimpleDateFormat("dd MMMMMMM yyyy").format(new Date());
        ((TextView) findViewById(R.id.header_date)).setText(dateString);
    }

    private void initButton() {

    	mflipper = ((ViewFlipper) this.findViewById(R.id.flipper));
        mflipper.setInAnimation(AnimationUtils.loadAnimation(this,
                R.anim.slide_left));

        Button homeButton = (Button) findViewById(R.id.button_home);
        homeButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(0);
			}
		});

        Button jadwalKunjunganButton = (Button) findViewById(R.id.button_jadwal_kunjungan);
        jadwalKunjunganButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(1);
			}
		});
        
        Button addPesananButton =(Button) findViewById(R.id.button_add_pesanan);
        addPesananButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(2);
			}
		});
        Button addTokoButton = (Button)findViewById(R.id.button_add_toko);
        addTokoButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(3);		
			}
		});
        Button listBarangButton = (Button) findViewById(R.id.button_list_barang);
        listBarangButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(4);
			}
		});
        
                
        Button infoDiskonButton =(Button)findViewById(R.id.button_info_diskon);
        infoDiskonButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(5);
			}
		});
        
        Button listPesananButton = (Button)findViewById(R.id.button_list_pesanan);
        listPesananButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(6);
			}
		});
                
        Button settingsButton = (Button)findViewById(R.id.button_settings);
        settingsButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(7);
				
			}
		});
        
        Button logoutButton = (Button)findViewById(R.id.button_logout);
        logoutButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				host.setCurrentTab(8);
				quit();
			}
		});
        
        
        
        
//		  System.out.println("invis : "+View.INVISIBLE);
//        if(tabMenu!=null){
//        	homeButton.setVisibility(tabMenu[0]);
//        	jadwalKunjunganButton.setVisibility(tabMenu[1]);
//        	addPesananButton.setVisibility(tabMenu[2]);
//        	addTokoButton.setVisibility(tabMenu[3]);
//        	listBarangButton.setVisibility(tabMenu[4]);
//        	listPesananButton.setVisibility(tabMenu[5]);
//        	infoDiskonButton.setVisibility(tabMenu[6]);
//        	logoutButton.setVisibility(tabMenu[7]);
//        	        	
//        }
    }

    private void actionScreen() {
        host = getTabHost();
        host.addTab(host.newTabSpec("Home").setIndicator("").setContent(new Intent(this, Home.class)));
        host.addTab(host.newTabSpec("JadwalKunjungan").setIndicator("").setContent(new Intent(this, JadwalKunjungan.class)));
        host.addTab(host.newTabSpec("AddPesanan").setIndicator("").setContent(new Intent(this, ListToko.class)));
        host.addTab(host.newTabSpec("AddToko").setIndicator("").setContent(new Intent(this, AddToko.class)));
        host.addTab(host.newTabSpec("ListBarang").setIndicator("").setContent(new Intent(this, ListBarang.class)));
        host.addTab(host.newTabSpec("InfoDiskon").setIndicator("").setContent(new Intent(this, InfoDiskon.class)));
        host.addTab(host.newTabSpec("ListPesanan").setIndicator("").setContent(new Intent(this, ListPesanan.class)));
        host.addTab(host.newTabSpec("Settings").setIndicator("").setContent(new Intent(this, Settings.class)));
//        host.addTab(host.newTabSpec("Logout").setIndicator("").setContent(new Intent(this, Logout.class)));
       // host.addTab(host.newTabSpec("Bola").setIndicator("").setContent(new Intent(this, Bola.class)));
       // host.addTab(host.newTabSpec("GayaHidup").setIndicator("").setContent(new Intent(this, GayaHidup.class)));
       // host.addTab(host.newTabSpec("Kesehatan").setIndicator("").setContent(new Intent(this, Kesehatan.class)));
      //  host.addTab(host.newTabSpec("LiputanAnda").setIndicator("").setContent(new Intent(this, LiputanAnda.class)));
    
        host.setCurrentTab(0);
    }
    
    
    public void quit() {
		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle("Exit");
		alertDialog.setMessage("Are you sure?");
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				finish();
			}
		});
		alertDialog.setIcon(R.drawable.icon);
		alertDialog.show();
	}
}
